<?php

//echo 'this is a simple string'.'<br/>';
//
//echo 'You can also have embedded newlines in 
//strings this way as it is
//okay to do'.'<br/>';
//
//// Outputs: Arnold once said: "I'll be back"
//echo 'Arnold once said: "I\'ll be back"'.'<br/>';
//
//// Outputs: You deleted C:\*.*?
//echo 'You deleted C:\\*.*?'.'<br/>';
//
//// Outputs: You deleted C:\*.*?
//echo 'You deleted C:\*.*?'.'<br/>';
//
//// Outputs: This will not expand: \n a newline
//echo 'This will not expand:\na newline'.'<br/>';
//
//// Outputs: Variables do not $expand $either
//echo "Variables do not $expand $either".'<br/>';
//
?>

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
echo $str.'<br/>';

/* More complex example, with variables. */
class foo
{
    var $foo;
    var $bar;

    function foo()
    {
        $this->foo = 'Foo';
        $this->bar = array('Bar1', 'Bar2', 'Bar3');
    }
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41<br/>
EOT;
var_dump(array(<<<EOD
foobar!
EOD
));

//$beer = 'Heineken';
//echo "$beer's taste is great"; // works; "'" is an invalid character for variable names
//echo "He drank some $beers";   // won't work; 's' is a valid character for variable names but the variable is "$beer"
//echo "He drank some ${beer}s"; // works
//echo "He drank some {$beer}s"; // works
?>

<?php
//error_reporting(E_ALL);
//
//$fruits = array('strawberry' => 'red', 'banana' => 'yellow');
//
//// Works, but note that this works differently outside a string
//echo "A banana is $fruits[banana].";
//
//// Works
//echo "A banana is {$fruits['banana']}.";
//
//// Works, but PHP looks for a constant named banana first, as described below.
//echo "A banana is {$fruits[banana]}.";
//
//// Won't work, use braces.  This results in a parse error.
//echo "A banana is {$fruits['banana']}.";
//
//// Works
//echo "A banana is " . $fruits['banana'] . ".";
//
//// Works
//echo "This square is $square->width meters broad.";
//
//// Won't work. For a solution, see the complex syntax.
//echo "This square is $square->width00 centimeters broad.";
//echo "<br/>+++<br/>";
//
//// Show all errors
//error_reporting(E_ALL);
//
//$great = 'fantastic';
//
//// Won't work, outputs: This is { fantastic}
//echo "This is { $great}"."<br/>";
//
//// Works, outputs: This is fantastic
//echo "This is {$great}"."<br/>";
//echo "This is ${great}"."<br/>";
//
//// Works
//echo "This square is {$square->width}00 centimeters broad."."<br/>"; 
//
//// Works
//echo "This works: {$arr[4][3]}"."<br/>";
//
//// This is wrong for the same reason as $foo[bar] is wrong  outside a string.
//// In other words, it will still work, but only because PHP first looks for a
//// constant named foo; an error of level E_NOTICE (undefined constant) will be
//// thrown.
//echo "This is wrong: {$arr[foo][3]}"."<br/>"; 
//
//// Works. When using multi-dimensional arrays, always use braces around arrays
//// when inside of strings
//echo "This works: {$arr['foo'][3]}"."<br/>";
//
//// Works.
//echo "This works: " . $arr['foo'][3]."<br/>";
//
//echo "This works too: {$obj->values[3]->name}"."<br/>";
//
//$name=x;
//$x=y;
//echo "This is the 1 value of the var named $name: {${$name}}"."<br/>";
//
////echo "This is the 2 value of the var named by the return value of getName(): {${getName()}}"."<br/>";
////
////echo "This is the 3 value of the var named by the return value of \$object->getName(): {${$object->getName()}}"."<br/>";
//
//$str = "this is test.";
//$first = $str[0];
//var_dump($first);
//$str[strlen($str)-1] = '!';
//var_dump($str);
//echo "<br/>", "<br/>";
//
//class StrValClass
//{
//    public function __TOSTRING()
//    {
//        return __CLASS__;
//    }
//}
//
//echo strval(new StrValClass);
//
//echo "This spans
//multiple lines. The newlines will be
//output as well";
//
//echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
//
//echo "Escaping characters is done \"Like this\".";
//
//$foo = "foobar";
//$bar = "barbaz";
//
//echo $foo,$bar;     // foobarbarbaz
//echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
//echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
//
//echo <<<END
//This uses the "here document" syntax to output
//multiple lines with $variable interpolation. Note
//that the here document terminator must appear on a
//line with just a semicolon. no extra whitespace!
//END;
//
//($some_var) ? print 'true' : print 'false';
//echo ($some_var) ? 'true' : 'false';
//

// variable function
/*function foo()
{
    echo "in foo()<br />\n";
}

function bar($arg1 = 0x123)
{
    echo "in bar(); argument is '$arg1'.<br />\n";
    var_dump($arg1);
}

function echoit($string)
{
    echo $string,'<br />';
}

$func='foo';
$func();

$func='bar';
// $func('ARG');
$func();

$func='echoit';
$func('testtest');

$func='echo';
//$func('echo');
echo('echo');
 */

/*
class Foo
{
    public function f1($arg = 'f1')
    {
        $name='bar';
        $this->$name($arg);
    }

    public function bar($arg = 'bar')
    {
        echo "in Foo->bar(). arg is '$arg'. <br />\n";
    }
}

$foo=new Foo();
$funcname='f1';
$foo->$funcname(1234);
*/

/*
print("Hello World");

print "print() also works without parentheses.";

print "This spans
multiple lines. The newlines will be
output as well";

print "This spans\nmultiple lines. The newlines will be\noutput as well.";

print "escaping characters is done \"Like this\".";

// You can use variables inside of a print statement
$foo = "foobar";
$bar = "barbaz";

print "foo is $foo"; // foo is foobar

// You can also use arrays
$bar = array("value" => "foo");

print "this is {$bar['value']} !"; // this is foo !

// Using single quotes will print the variable name, not the value
print 'foo is $foo'; // foo is $foo

// If you are not using any other characters, you can just print variables
print $foo;          // foobar

print <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END;
 */

/*
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
$b=print_r ($a, true);
print $b;
 */

?>

<?php
/*$string="I'm a string";
$bstring1=(binary)$string;
$bstring2=b"bs";

var_dump($string, $bstring1, $bstring2);

$foo = 10;
$str = "$foo";
$fst = (string)$foo;

if ($fst === $str)
{
    echo "<br/>" . "same: ";
    var_dump($str, $fst);
}*/
?>
